<template>
	<view class="imagePage">

		<!-- 推荐好友 -->
		<view class="recommend">
			<view class="sjrz" style="margin: 40rpx auto ;text-align: center;">
				团洗用户推广
			</view>
			<view class="content">
				<image class="codeTwo" :src="promotion_code" mode="" ></image>
				<view class="title">
					<view class="getCode">专属邀请码</view>
					<view class="dash">
						{{ promotion_url }}
						 <view class="btn1" id="btn" @click="copyText()">复制</view>
					</view>
					<view class="">扫码邀请>推广有礼>权益享受</view>
					<view class="longPush" >长按图片保存到相册</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getPromotionCode
	} from '@/request/api.js'
	export default {
		data() {
			return {
				promotion_code: '',
				promotion_url: ''
			};
		},
		onLoad(el) {
			this.getPageData()
		},
		methods: {
			// 推荐好友
			async getPageData() {
				let res = await getPromotionCode()
				this.promotion_code = res.data.promotion_code
				this.promotion_url = res.data.promotion_url
				console.log(res,11)
			},
			// 点击下载图片
			downloadImage() {
				let that = this
				uni.downloadFile({
					url: that.img_hb,
					success(res) {
						let tempFilePath = res.tempFilePath
						uni.saveImageToPhotosAlbum({
							filePath: tempFilePath,
							success(res1) {
								that.$utils.toast('图片生成成功')
							},
							fail(err) {
								that.$utils.toast('图片生成失败')
							}
						})
					}
				})
			},
			// 复制
			copyText() {
				let textarea = document.createElement("textarea")
				textarea.value = this.promotion_url
				textarea.readOnly = "readOnly"
				document.body.appendChild(textarea)
				textarea.select() // 选中文本内容
				textarea.setSelectionRange(0, this.promotion_url.length) 
				uni.showToast({//提示
					title:'复制成功' 
				})
				document.execCommand("copy")
				textarea.remove()
			}
		}
	}
</script>

<style lang="less">

	.sjrz {
		text-align: center;
		box-shadow: 0px 0px 5px rgba(151, 151, 151, 0.1);
		box-sizing: border-box;
		border-radius: 5px;
		width: 100%;
		padding: 20rpx;
		background: #fff;
	}


	.title2{
		width:106%;
		image{
			width: 100%;
		}
	}
	.imagePage {
		padding: 20rpx;

		.recommend {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.content {
				box-shadow: 0px 0px 5px rgba(151, 151, 151, 0.1);
				box-sizing: border-box;
				border-radius: 5px;
				background: #fff;
				width: 100%;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20rpx;
				.longPush{
					color: #2CB9A4;
				}
			}

			.title {
				width: 100%;
				text-align: center;
				display: flex;
				flex-direction: column;
				align-items: center;

				view {
					line-height: 50rpx;
					font-size: 28rpx;
				}
			}

			
			.getCode{
				margin: 20rpx;
			}
			.dash {
			    font-size: 14px;
			    width: 95%;
			    padding: 11px 0 0 0;
			    border-top: 1px dashed #979797;
			}

			.codeTwo {
				width: 350rpx;
				height: 350rpx;

			}

			.btn1 {
				color: #409eff;
				font-size: 14px;
				margin-left: 10px;
				display: inline-block;
			}

			.invitation {
				background: #1FC064;
				color: #fff;
				bottom: 200rpx;
				left: 50%;
				transform: translateX(-50%);
			}

			.generate {
				background: #DCDCDC;
				color: #7F8084;
				bottom: 70rpx;
				left: 50%;
				transform: translateX(-50%);
			}
		}

		.PKWin,
		.PKNegative {
			image {
				width: 100%;
				height: 100%;
			}

			.btn {
				width: 80%;
				height: 96rpx;
				line-height: 96rpx;
				text-align: center;
				border-radius: 96rpx;
				font-size: 28rpx;
				font-weight: 500;
				position: fixed;
				background: #000;
				color: #fff;
				bottom: 240rpx;
				left: 50%;
				transform: translateX(-50%);
			}
		}

	}
</style>